/*
 * ComputeAblationHeatfluxMaterial.C
 *
 *  Created on: Feb 4, 2020
 *      Author: liuxiao
 */

#include<iostream>

#include "../../include/materials/ComputeAblationHeatfluxMaterial.h"
#include "libmesh/quadrature.h"
#include "libmesh/system.h"
#include "libmesh/radial_basis_interpolation.h"
using std::cout;
using std::endl;
registerMooseObject("TrilobitaApp", ComputeAblationHeatfluxMaterial);
template<>
InputParameters validParams<ComputeAblationHeatfluxMaterial>()
{
	InputParameters params = validParams<Material>();
	params.addRequiredCoupledVar("temperature_varialble", "Coupled wall temperature");
	return params;
}


ComputeAblationHeatfluxMaterial::ComputeAblationHeatfluxMaterial(const InputParameters & parameters) :
    	    										Material(parameters),
	_hw(declareProperty<Real>("wall_enthalpy")),
	_hc(declareProperty<Real>("carbon_enthalpy")),
	_qh(declareProperty<Real>("hotwall_heatflux")),
	_qrad_out(declareProperty<Real>("heatflux_rad_out")),
	_qn(declareProperty<Real>("net_heatflux")),
	_Cw_C1(getMaterialProperty<Real>("Cw_C1")),
	_Cw_C2(getMaterialProperty<Real>("Cw_C2")),
	_Cw_C3(getMaterialProperty<Real>("Cw_C3")),
	_Cw_C4(getMaterialProperty<Real>("Cw_C4")),
	_Cw_C5(getMaterialProperty<Real>("Cw_C5")),
	_Cw_O2(getMaterialProperty<Real>("Cw_O2")),
	_Cw_O(getMaterialProperty<Real>("Cw_O")),
	_Cw_CO(getMaterialProperty<Real>("Cw_CO")),
	_Cw_CO2(getMaterialProperty<Real>("Cw_CO2")),
	_Cw_N2(getMaterialProperty<Real>("Cw_N2")),
	_Cw_N(getMaterialProperty<Real>("Cw_N")),
	_Cw_CN(getMaterialProperty<Real>("Cw_CN")),
	_Cw_C2N(getMaterialProperty<Real>("Cw_C2N")),
	_qc(getMaterialProperty<Real>("coldwall_heatflux")),
	_hr(getMaterialProperty<Real>("recovery_enthalpy")),
	_Tw_qc(getMaterialProperty<Real>("Tw_for_coldwall_heatflux")),
	_epsilon(getMaterialProperty<Real>("surface_emissivity")),
	_mc(getMaterialProperty<Real>("mc")),
	_injection_coff(getMaterialProperty<Real>("injection_coff")),
	_temperature(coupledValue("temperature_varialble")),
	_sigma(5.67e-08)

{

}



Real ComputeAblationHeatfluxMaterial::compute_hw(Real Tw)
{
	return 1000*Tw;
}

Real ComputeAblationHeatfluxMaterial::compute_hc(Real Tw)
{
	return 0;
}

void ComputeAblationHeatfluxMaterial::computeProperties()
{

	for (unsigned int qp(0);qp < _qrule->n_points(); ++qp)
	{
		_hw[qp]=compute_hw(_temperature[qp]);
		_hc[qp]=compute_hc(_temperature[qp]);
		if(abs(_hr[qp]-_hw[qp])<=1)
		{
			_qh[qp]=0;
		}
		else
		{
			_qh[qp]=_qc[qp]*(_hr[qp]-_hw[qp])/(_hr[qp]-compute_hw(_Tw_qc[qp]));
		}
		_qrad_out[qp]=_epsilon[qp]*_sigma*pow(_temperature[qp],4);
		_qn[qp]=_injection_coff[qp]*_qh[qp]-_mc[qp]*_hc[qp]-_qrad_out[qp];
	}

}




